import * as api from '@/api/employee.js'

export default {
  namespaced: true,
  state: {
    list: [],
    total: 0,
    permission: {}
  },
  mutations: {
    SET_LIST(state, newList) {
      state.list = newList
    },
    SET_TOTAL(state, newTotal) {
      state.total = newTotal
    },
    SET_PERMISSTION(state, newPermission) {
      state.permission = newPermission
    }
  },
  actions: {
    async updateList(context, params) {
      const res = await api.getEmployeeList(params)
      context.commit('SET_LIST', res.rows)
      context.commit('SET_TOTAL', res.total)
    },
    updatePermission(context) {
      const permission = api.getPermission()
      context.commit('SET_PERMISSTION', permission)
    }
  }
}
